<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var objs = frames['rCustomerFrame'].document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("<fmt:message key='repeatCustomer.message.main'/>");
			return false;
		}
		return true;
	}

	function searchCustomer(){
		var customerName = document.getElementById("customerName");
		if(customerName.value == ""){
			alert("<fmt:message key='openSea.message.search'/>");
		}else{
			document.getElementById("sFlag").value = "1";
			document.repeatCustomerForm.action = "./repeatCustomer.do";
			document.repeatCustomerForm.target = "main";
			document.repeatCustomerForm.submit();
		}
	}
	
	function mergeCustomer(){
		if(checkForm()){
			var selectCustomerId = frames['rCustomerFrame'].document.getElementById("selectCustomerId").value;
			var objs = frames['rCustomerFrame'].document.getElementsByName("id");
			var mainCustomerId = "";
			for(var i = 0; i < objs.length; i++){
				if(objs[i].checked){
					mainCustomerId = objs[i].value;
					break;
				}
			}
		
			if(confirm("<fmt:message key='repeatCustomer.message.isSalePerson'/>")){
				personDialog(selectCustomerId,mainCustomerId);
			}else{
				document.repeatCustomerForm.action = "./repeatCustomer.do?action=mergeCustomer&selectCustomerId="+selectCustomerId+"&mainCustomerId="+mainCustomerId;
				document.repeatCustomerForm.target = "main";
				document.repeatCustomerForm.submit();
			}
		}
	}
	
	function personDialog(selectCustomerId,mainCustomerId){
		var url = "./exceptionCustomer.do?action=preSelectPerson";
		var dlgParam = "dialogHeight:400px;dialogWidth:500px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		if(checkForm()){
			var rt = window.showModalDialog(url,"",dlgParam);
			if(rt != undefined && rt != ""){			
				//根据从子窗口得到销售负责人id,未使用个数,是否例外销售负责人
				var salePersonId = "";
				var notUseCustomerNum = "";
				var isExpUser = "";
				var tStr = rt.split(",");
				if(tStr[0] != "" && tStr[1] != ""){
					salePersonId += tStr[0];
					notUseCustomerNum += tStr[1];
				}
				isExpUser = tStr[2];
				
				if(isExpUser == '1' || notUseCustomerNum > 0){
					document.repeatCustomerForm.action = "./repeatCustomer.do?action=mergeCustomer&salePersonId="+salePersonId+"&selectCustomerId="+selectCustomerId+"&mainCustomerId="+mainCustomerId;
					document.repeatCustomerForm.target = "main";
					document.repeatCustomerForm.submit();
				}else{
					alert("<fmt:message key='repeatCustomer.message.overstep'/>");
				}
			}
		}
	}
	
	function pageCustomer(flag){
		document.repeatCustomerForm.action = "./repeatCustomer.do?action=display&flag="+flag;
		document.repeatCustomerForm.target = "main";
		document.repeatCustomerForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='repeatCustomer.message.mergeSuccess'/>");
		}
		
		if("<c:out value='${deleteResult}'/>" == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="repeatCustomerForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab" colspan="2">报备管理</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;"><fmt:message key='openSea.lable.search'/>
							<input id="customerName" name="customerName" class="input_query" type="text" value="${customerName}"/>
							<input id="sFlag" name="sFlag" type="hidden" value="${sFlag}"/>
							<a class="search" href="javascript:searchCustomer();" target="main" hidefocus="true">查询</a>
							|
							<c:if test="${isMergeCustomer == 1}">
							<a class="merge" href="javascript:mergeCustomer();" title="<fmt:message key='repeatCustomer.button.merge'/>" hidefocus="true"><fmt:message key='repeatCustomer.button.merge'/></a>
							</c:if>
						</td>
						<td></td>
					</tr>
					<tr><td height="2" colspan="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab">重复客户</td>
						<td align="right" valign="">
							<!-- page -->
							<table class="table_page2">
								<tr>
									<td valign="bottom">
										<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
										<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
										<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
										共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr><td colspan="3" height="2"></td></tr>
					<tr>
						<td colspan="2">
							<table class="table">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style">
											<tr>
												<td class="title" width="8"></td>
												<td class="title"><fmt:message key='customer.lable.customerName'/></td>
												<td class="title" width="15%"><fmt:message key='customer.lable.saleperson'/></td>
												<td class="title" width="15%"><fmt:message key='customer.lable.lastlink'/></td>
											</tr>
											<c:forEach var="customer" items="${customers}">
											<tr onmouseover="onmousemoveChange(this,'img${customer.id}')" onmouseout="onmouseoutChange(this,'img${customer.id}')">
												<td height="16" width="8" align="right"><img id="img${customer.id}" src="./images/table_sign2.bmp"></td>
												<td align="left">&nbsp;&nbsp;
													<a href="./repeatCustomer.do?action=repeatCustomerInfo&id=${customer.id}" target="rCustomerFrame">${customer.customerName}</a>
												</td>
												<td>${customer.salePerson}</td>
												<td><fmt:formatDate value="${customer.lastLink}" pattern="yyyy-MM-dd"/></td>
											</tr>
											</c:forEach>
										</table>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
								<tr>
									<td align="left" valign="bottom">
										<!-- page -->
										<table id="tp" class="table_page">
											<tr>
												<td>&nbsp;&nbsp;
													<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
													<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
													<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
													共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td class="" valign="top"><br>
										<iframe src="./repeatCustomer.do?action=repeatCustomerInfo" id="rCustomerFrame" name="rCustomerFrame" frameborder="0" scrolling="no" width="100%" 
											onload="this.height=rCustomerFrame.document.body.scrollHeight"></iframe>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body> 
</html>